/** 
 * interface URL to the app server
 */
var api = 'http://ultradigital.de/joel/api.php';
var phpsessid = '';

/**
 * request object for talking to the app server
 */
var request = function(query, data, callback) {
	
	var packet = {parameter: data};
	var classname = query.split(":");
	
	if (typeof classname[1] != "undefined") {
		packet.method = classname[1];
		packet.classname = classname[0];
		
	} else {
		packet.method = classname[0];
		packet.classname = 'joel';
	}
	
	var c = Titanium.Network.createHTTPClient();
		c.setRequestHeader("contentType","application/json; charset=utf-8");
		c.onreadystatechange = function() {
			$('status').innerHTML = this.readyState;
			if(this.readyState == 4) {
				if(typeof callback == 'function') {
					callback(JSON.decode(this.responseText));
				}
			}
		}
		
		if (Titanium.App.Properties.hasProperty('sessionid') || Titanium.App.Properties.getString('sessionid') != '') { 
			phpsessid = '&PHPSESSID='+Titanium.App.Properties.getString('sessionid');
		}
		
		c.open('POST', api);
		c.send('json='+JSON.encode(packet)+'&PHPSESSID='+phpsessid);
};
